// pages/adress/adress.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type:"",
    dataList: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var type = JSON.parse(options.type);
    if(type){
      this.setData({
        type: type
      })
    }
    // this.getAdress();
  },

  cellClick:function(e){
    var that = this;
    var item = e.currentTarget.dataset.item;
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2];
    
    if(that.data.type == "1"){
      prevPage.setData({
        up_adress: item
      })
    }
    if (that.data.type == "2") {
      prevPage.setData({
        down_adress: item
      })
    }
    if (that.data.type != "3") {
      wx.navigateBack({
        delta: 1
      })
    }
  },
  imgClick:function(e){
    console.log(e)
    var item = e.currentTarget.dataset.item;
    var items = JSON.stringify(item)
    wx.navigateTo({
      url: '../addAdress/addAdress?item=' + items
    })
  },
  getAdress:function(e){
    const that = this;
    const user = wx.getStorageSync("we_userInfo");
    if(user){
      wx.request({
        url: getApp().globalData.requestURL + '/api/userAddress/getAddress',
        data: {
          userId: user.user.userId
        },
        header: {
          "content-type": "application/json"
        },
        method: 'POST',
        success: function (res) {
          console.log(res.data.result)
          that.setData({
            dataList: res.data.result
          })
        },
        fail: function (err) {
          console.log(err.errMsg)
        }

      })
    }else{
      console.log("获取地址管理失败 userid没有")
    }
  },
  add_adress:function(e){
    wx.navigateTo({
      url: '../addAdress/addAdress?item=1',
    })
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getAdress();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})